package com.huatai.datacenter.controller.dataquality;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.datacenter.entity.dataquality.QualityLogDetailEntity;
import com.huatai.datacenter.entity.dataquality.QualityLogEntity;
import com.huatai.datacenter.service.QualityLogDetailService;
import com.huatai.datacenter.service.QualityLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gusiyi
 * @version 1.0
 * @className QualityLogController
 * @description 描述：
 * @date 2023/6/5 15:11
 */
@Api(value = "数据质量日志",tags = "数据质量日志")
@RequestMapping("/dataQuality/log")
@RestController
public class QualityLogController {

	@Autowired
	private QualityLogService qualityLogService;

	@Autowired
	private QualityLogDetailService detailService;


	@RequestMapping("/getList")
	@ApiOperation("获取数据质量日志清册")
	@ApiOperationSupport(order = 1, includeParameters = {
		"qualityLogEntity.pageIndex",
		"qualityLogEntity.pageSize",
		"qualityLogEntity.dataModelName"
	})
	public R<Page<QualityLogEntity>> getList(@RequestBody QualityLogEntity qualityLogEntity){
		Page<QualityLogEntity> page = qualityLogService.getQualityLogList(qualityLogEntity);
		return R.data(page,"获取数据质量日志清册成功");
	}

	@RequestMapping("/getLogDetailList")
	@ApiOperation("查看错误日志详情清册")
	@ApiOperationSupport(order = 2,includeParameters = {
		"qualityLogDetailEntity.qualityLogId",
		"qualityLogDetailEntity.pageIndex",
		"qualityLogDetailEntity.pageSize",
		"qualityLogDetailEntity.qualityRuleId",
		"qualityLogDetailEntity.startTime",
		"qualityLogDetailEntity.endTime"
	})
	public R<Page<QualityLogDetailEntity>> getLogDetail(@RequestBody QualityLogDetailEntity qualityLogDetailEntity){
		Page<QualityLogDetailEntity> logDetailEntityPage = detailService.getLogDetailList(qualityLogDetailEntity);
		return R.data(logDetailEntityPage,"获取错误日志详情清册成功");
	}

	@RequestMapping("/deleteByIds")
	@ApiOperation("删除质量日志清册")
	@ApiOperationSupport(order = 3,includeParameters = {
		"qualityLogEntity.id"
	})
	public R<QualityLogEntity> deleteByIds(@RequestBody List<QualityLogEntity> qualityLogEntity){
		return R.status(qualityLogService.deleteByIds(qualityLogEntity));
	}

	@RequestMapping("/addErrLogDetail")
	@ApiOperation(value = "(后台使用)添加错误日志信息",notes = "后台通过QualityLogService调用")
	@ApiOperationSupport(order = 4,includeParameters ={
		"qualityLogDetailEntity.qualityLogId",
		"qualityLogDetailEntity.qualityRuleId",
		"qualityLogDetailEntity.qualityRuleName",
		"qualityLogDetailEntity.fieldId",
		"qualityLogDetailEntity.fieldName",
		"qualityLogDetailEntity.sourceData",
		"qualityLogDetailEntity.remark",
		"qualityLogDetailEntity.executeTime",
		"qualityLogDetailEntity.nextExecuteTime"
	})
	public R<Object> addErrLogDetail(@Valid @RequestBody QualityLogDetailEntity qualityLogDetailEntity){
		return R.status(qualityLogService.addErrLogDetail(qualityLogDetailEntity));
	}
}
